﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using SharePointCommander.Model;
using SharePointCommander.Model.PropertySheet;

namespace SharePointCommander
{
    public class PropertyValueSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (item != null && item is PropertyItem)
            {
                PropertyItem propItem = item as PropertyItem;
                Type type = propItem.GetType();
                if (propItem is PropertyItemString)
                {
                    return (container as ContentPresenter).FindResource("DataTemplateText") as DataTemplate;
                }
                else if (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(PropertyItemInt<>)))
                {
                    return (container as ContentPresenter).FindResource("DataTemplateText") as DataTemplate;
                }
                else if (propItem is PropertyItemChoice)
                {
                    return (container as ContentPresenter).FindResource("DataTemplateCombobox") as DataTemplate;
                }
                else if (propItem is PropertyItemBoolean)
                {
                    return (container as ContentPresenter).FindResource("DataTemplateCheckbox") as DataTemplate;
                }
                else if (propItem is PropertyItemDateTime)
                {
                    return (container as ContentPresenter).FindResource("DataTemplateDatetime") as DataTemplate;
                }
                else if (propItem is PropertyItemArray)
                {
                    return (container as ContentPresenter).FindResource("DataTemplateArray") as DataTemplate;
                }
                else if (propItem is PropertyItemException)
                {
                    return (container as ContentPresenter).FindResource("DataTemplateException") as DataTemplate;
                }
                else if (propItem is PropertyItemGuid)
                {
                    return (container as ContentPresenter).FindResource("DataTemplateGuid") as DataTemplate;
                }
                else if (propItem is PropertyItemObject)
                {
                    return (container as ContentPresenter).FindResource("DataTemplateObject") as DataTemplate;
                }
                else
                {
                    return (container as ContentPresenter).FindResource("DataTemplateText") as DataTemplate;
                }
            }
            else
            {
                return (container as ContentPresenter).FindResource("DataTemplateText") as DataTemplate;
            }
        }
    }
}
